from django.contrib import admin

# Register your models here.
from .models import Product, Units, Suppliers, Clients, GoodsCategory


class GoodsTabularInline(admin.TabularInline):
    model = Product
    extra = 1
    list_display = ('name', 'color', 'code')


class GoodsAdmin(admin.ModelAdmin):
    fields = ('goods_id', 'name', 'code', 'category', 'color', 'unit')
    # list_display = ('goods_name', 'goods_price', 'goods_num', 'goods_description', 'goods_image', 'goods_category')
    # list_filter = ('goods_category', 'goods_price')
    # search_fields = ('goods_name', 'goods_price', 'goods_num', 'goods_description', 'goods_image', 'goods_category')
    # list_per_page = 10
    # list_editable = ('goods_price', 'goods_num', 'goods_description', 'goods_image', 'goods_category')
    # list_display_links = ('goods_name', 'goods_price', 'goods_num', 'goods_description',
    # 'goods_image', 'goods_category')
    # list_select_related = ('goods_category',)
    # list_display_links = ('code', 'category', 'name')
    list_display = ('name', 'color', 'code')
    # list_filter = ('code', 'name')
    list_per_page = 20
    search_fields = ('name', 'code')
    # list_editable = ['name']


admin.site.register(Product, GoodsAdmin)
# @admin.register(Goods)
# class GoodsAdmin(admin.ModelAdmin):
#     list_display = ['name', 'price']
#     list_editable = ['price']
#     list_display_links = ['name']


@admin.register(Units)
class UnitsAdmin(admin.ModelAdmin):
    list_display = ('unit_name', 'code')
    fields = ('unit_name', 'code')
    list_per_page = 20


@admin.register(Suppliers)
class SuppliersAdmin(admin.ModelAdmin):
    list_display = ('name', 'address', 'contact', 'phone')
    fields = ('name', 'contact')
    list_per_page = 20
    # inlines = [GoodsTabularInline]


@admin.register(Clients)
class ClientsAdmin(admin.ModelAdmin):
    list_display = ('name', 'address', 'contact', 'phone')
    fields = ('name', 'contact')
    list_per_page = 20


@admin.register(GoodsCategory)
class GoodsCategoryAdmin(admin.ModelAdmin):
    list_display = ('category_name', 'code')
    fields = ('category_name', 'category_code')
    list_per_page = 20
